package cn.xcstudenth.myapplication.fragment;

import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import java.util.List;

import cn.xcstudenth.myapplication.R;
import cn.xcstudenth.myapplication.webviewutils.WebViewUtils;

/**
 * Created by 赵航 on 2020/8/13.
 * WeChat: zhao--hang--
 */
public class WebViewHtmlFragment extends Fragment {
    private View         mView;
    private List<String> mData;
    private WebView mWebView;

    public WebViewHtmlFragment(List<String> list) {
        this.mData = list;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        mView = inflater.inflate(R.layout.fragment_web_html, null);
        initView(mView);
        return mView;
    }

    private void initView(View view) {
        mWebView = (WebView) view.findViewById(R.id.web_view);
        StringBuilder builder = new StringBuilder();
        for (String datum : mData) {
            builder.append(datum);
            builder.append("\\n\\r");
        }
        WebViewUtils.setWebHtml(mWebView,builder.toString());

    }
}
